package com.ccnf.web.controller;


import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.baomidou.mybatisplus.plugins.Page;
import com.ccnf.core.bean.ResponseWithData;
import com.ccnf.core.bean.ResponseWithPage;
import com.ccnf.model.entity.MessagePoint;
import com.ccnf.service.MessagePointService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import org.springframework.stereotype.Controller;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author developer
 * @since 2018-06-14
 */
@RestController
@RequestMapping("/message/points")
@Api(value = "MessagePointController", description = "消息节点相关API")
public class MessagePointController {
    @Autowired
    private MessagePointService messagePointService;

    @ApiOperation("录入消息节点信息")
    @PostMapping
    public ResponseWithData add(@RequestBody MessagePoint messagePoint) {
        messagePointService.insert(messagePoint);
        return ResponseWithData.success(messagePoint.getPointId());
    }

    @ApiOperation("获取消息节点信息列表")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "userId", value = "当前用户ID", paramType = "query"),
            @ApiImplicitParam(name = "pageNum", value = "当前页，默认1", defaultValue = "1", paramType = "query"),
            @ApiImplicitParam(name = "pageSize", value = "每页显示几条，默认5", defaultValue = "5", paramType = "query")
    })
    @GetMapping
    public ResponseWithPage page(Long userId,
                                 @RequestParam(required = false) Long expoId,
                                 @RequestParam(required = false, defaultValue = "1") Integer pageNum,
                                 @RequestParam(required = false, defaultValue = "5") Integer pageSize) {
        Page<MessagePoint> page = new Page(pageNum, pageSize);
        page.setSearchCount(false);
        page = messagePointService.findMessagePointByUserId(expoId, userId, page);
        return ResponseWithPage.success(page.getRecords(), pageNum, pageSize);
    }
}

